import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
/*获取文件的真实路径，是指项目部署以后发布发的路径
* ServletContext
* 获取真实路径的方法
* 采用ServleContext类李的方法 getRealPatg（String path)
* */
@WebServlet("/servleContextDemo4")
public class ServleContextDemo4 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletContext context=this.getServletContext();
        String realPath = context.getRealPath("/b.txt");//web目录下资源访问
    /*
    *
    * http://localhost:8080/yzm

    *web-if 下面有个a.html
    * http://localhost:8080/responsedemo/WEB-INF/c.txt
    *
    * */
        System.out.println(realPath);
        /*src目录下的资源访问路径
        * src下面的所有文件都会放在WEB-INF下面的classes文件里
        *
        * */
        String realPath1 = context.getRealPath("/WEB-INF/classes/a.txt");
        System.out.println(realPath1);
    }
}
